<template>
	<view class="consumer-detail">
		<uni-nav-bar class="uni-nav-bar" color="#ffffff" left-icon="left" @clickLeft="togo" title="我的余额" :border="false"
			fixed statusBar></uni-nav-bar>
		<view class="consumer-detail__topbox">
			<!-- <view class="balance">¥{{ userInfo.balance }}</view> -->
			<!-- <view class="cash-btn">提现</view> -->
		</view>
		<view class="consumer-detail__list">
			<view class="title">我的余额(元)</view>
			<view class="price">{{userInfo.balance}}</view>
			<view class="btnbox">
				<view class="btnlist" style="background-color: rgba(47,204,113,.1);color: #2FCC71;" @click="tourl1">充值
				</view>
				<view class="btnlist" style="background-color: #2FCC71;color: #ffffff;" @click="tourl2">提现</view>
			</view>
		</view>
		<view class="listbox">
			<view class="title">余额变更明细</view>
			<view v-if="listData.length">
				<view class="list" v-for="(item,index) in listData" :key="index">
					<view class="toplist">
						<text>{{item.remark}}</text>
						<text v-show="item.amount > 0">+¥{{Number(item.amount).toFixed(2)}}</text>
						<text v-show="item.amount <= 0">{{Number(String(item.amount)).toFixed(2)}}</text>
					</view>
					<view class="buttonlist">
						<text>{{item.time}}</text>
						<text>余额 {{Number(item.hamount).toFixed(2)}}元</text>
					</view>
				</view>
			</view>
			<view v-else>暂无明细</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex'
	export default {
		data() {
			return {
				loadMore: true,
				pageNum: 1,
				pageSize: 20,
				listData: [], // 精选推荐列表数据
			}
		},
		onShow() {
			this.listData = [];
			this.getList()
			this.getUserInfo()
		},
		computed: {
			...mapState(['userInfo'])
		},
		// 下拉刷新
		onPullDownRefresh() {
			uni.showNavigationBarLoading()
			this.refresh()
			uni.hideNavigationBarLoading()
			uni.stopPullDownRefresh()
		},
		// 上拉加载更多
		onReachBottom() {
			if (this.loadMore) {
				this.pageNum = this.pageNum + 1
				this.getList()
			}
		},
		methods: {
			...mapActions(['getUserInfo']),
			// 获取
			refresh() {
				this.loadMore = true
				this.listData = []
				this.pageNum = 1
				this.getList()
			},
			// 获取明细列表
			async getList() {
				const data = await this.$apis.user.getBalance({
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					type: 2
				})
				this.listData = [...this.listData, ...data.rows]
				if (this.listData.length >= data.total) {
					this.loadMore = false
				}
			},
			togo() {
				uni.navigateBack(-1)
			},
			tourl1() {
				uni.navigateTo({
					url: '/pages/mine/consumerDetail/Recharge'
				})
			},
			tourl2() {
				// uni.showToast({
				// 	title: '此功能还未开通权限',
				// 	icon: 'none'
				// })
				// return
				uni.navigateTo({
					url: '/pages/mine/consumerDetail/Withdrawal'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.consumer-detail {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		flex-direction: column;
		min-height: 100%;
		background-color: #F8F8F8;

		.consumer-detail__topbox {
			width: 750rpx;
			height: 296rpx;
			background-image: linear-gradient(to right, #1EB75E, #2FCC71);
			display: flex;
			flex-direction: column;
			align-items: center;

			.balance {
				font-size: 60rpx;
				font-weight: bold;
				color: #FFFFFF;
				margin-top: 100rpx;
			}

			.cash-btn {
				width: 216rpx;
				height: 64rpx;
				background: #FFFFFF;
				border-radius: 32rpx;
				margin-top: 76rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 30rpx;
				font-weight: bold;
				color: #FB5C26;
			}
		}

		.consumer-detail__list {
			width: 702rpx;
			height: 384rpx;
			background: #FFFFFF;
			border-radius: 10rpx;
			margin-top: -235rpx;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			flex-direction: column;
			padding-top: 48rpx;
			box-sizing: border-box;

			.title {
				color: #333333;
				font-size: 30rpx;
			}

			.price {
				font-size: 90rpx;
				color: #333333;
				font-weight: 700;
				margin-top: 24rpx;
				height: 84rpx;
			}

			.btnbox {
				margin-top: 42rpx;
				display: flex;
				justify-content: space-evenly;
				align-items: center;
				width: 100%;

				.btnlist {
					display: flex;
					justify-content: center;
					align-items: center;
					width: 304rpx;
					height: 96rpx;
					font-weight: 700;
					font-size: 30rpx;
					border-radius: 48rpx;
				}
			}
		}

		.listbox {
			display: flex;
			justify-content: flex-start;
			flex-direction: column;
			background-color: #ffffff;
			border-radius: 24rpx;
			padding: 32rpx;
			box-sizing: border-box;
			width: 702rpx;
			margin-top: 40rpx;
			margin-bottom: 80rpx;

			.title {
				font-weight: 700;
				color: #333333;
				font-size: 30rpx;
				margin-bottom: 24rpx;
			}

			.list {
				height: 134rpx;
				padding: 28rpx 0 24rpx;
				box-sizing: border-box;
				border-bottom: 2rpx solid #F2F2F5;

				.toplist {
					display: flex;
					justify-content: space-between;
					align-items: center;
					height: 44rpx;

					text {
						font-weight: 700;

						&:nth-of-type(1) {
							color: #000000;
							font-size: 26rpx;
						}

						&:nth-of-type(2) {
							color: #FB4041;
							font-size: 30rpx;
						}

						&:nth-of-type(3) {
							color: #2FCC71;
							font-size: 30rpx;
						}
					}
				}

				.buttonlist {
					margin-top: 5rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					text {
						color: rgba(0, 0, 0, .4);
						font-size: 24rpx;
					}
				}

				&:last-child {
					border: none;
				}
			}
		}
	}
</style>
<style lang="scss">
	.uni-navbar__content {
		background-image: linear-gradient(to right, #1EB75E, #2FCC71);
	}

	label {
		display: flex;
		align-items: center;
	}

	.uni-navbar__header {
		background-color: transparent !important;
	}

	.uni-nav-bar-text {
		font-size: 32rpx !important;
	}
</style>